<?php require_once('./header.php');

$sfile = file('./storage/private/settings.php');
foreach ($sfile as $line) {
    if (substr($line,0,10)=='comicexts@') {
        $settingdb = load_db('setting');
        $settingdb->save(array('name'=>'comicexts','type'=>'array','value'=>explode('|',substr(rtrim($line),11))),'comicexts');
    }
}


// Delete old files
$deletes = array(
    'admin.php','changelog.txt','license.txt','action.php',
    'open.php','lang.php','lock.php',
    
    'img/adminicon.png','img/comicman.png','img/date.png','img/flow.png',
    'img/mascot.png','img/reset.gif','img/tab-bl.png','img/tab-br.png',
    'img/templateman.png','img/title.png','img/userman.png','img/x.png',
    
    'inc/admin.css','inc/adminfooter.html','inc/adminheader.html',
    'inc/iefix.css','inc/lib.js','inc/login.html','inc/opera.css',
);
foreach ($deletes as $d) {
    if ($file = load_file('.../'.$d,true)) $file->delete();
}

// Delete whole folder
import('.../lib/filesystem.php');
$deletes = dir_array('.../plugins/');
foreach ($deletes as $d) {
    if ($file = load_file('.../plugins/'.$d,true)) $file->delete();
}
rmdir(makepath('.../plugins/'));

// Update RSS
if ($file = load_file('.../rss.xml',true)) {
    $file->write('<?xml version="1.0"?>
<redirect>
   <newLocation>'.get_config('baseurl').'inc/feed.php</newLocation>
</redirect>');
    
    $rd = 'Redirect 301 /'.foldername(dirname($_SERVER['PHP_SELF'])).'rss.xml  '.get_config('baseurl').'inc/feed.php';
    if ($file = load_file('.../.htaccess',true)) {
        $file->write($rd."\n".$file->read('string'));
    } else {
        $file = load_file('.../.htaccess');
        $file->write($rd);
    }
}

// Site file regeneration
$filecpu = load_cpu('file');
$filecpu->rebuild();

// Plugin Installation
$plugincpu = load_cpu('plugin');
$plugins = dir_array('.../lib/plugins/');
foreach ($plugins as $plugin) {
    if (!$plugincpu->get(substr($plugin,0,strlen($plugin)-4))) {
        $plugincpu->add(array(),array(
            'tmp_name'=>'.../lib/plugins/'.$plugin,
            'name'=>$plugin,
        ));
    }
}






// Delete upgrader
function delete_r($dir) {
    $handle = opendir($dir);
    while ($f = readdir($handle)) {
        if (is_dir($dir.$f)) {
            if ( ($f != '.') && ($f != '..') ) {
                delete_r($dir.$f.'/');
                rmdir($dir.$f.'/');
            }
        } else {
            unlink($dir.$f);
        }
    }
}

delete_r(makepath('.../upgrade/'));
rmdir(makepath('.../upgrade/'));
?>
        <h1>All Done!</h1>
        
        <h2>A ComicCMS 0.2 Primer</h2>
        <p>All the files on your website have been updated, now just to update your knowledge. Just a few less-obvious things:
        <br /><br />&bull; Your admin panel is now a folder called admin/ not a file called admin.php. You may want to update your bookmarks accordingly.
        <br /><br />&bull; News posts and comic blurbs now support BBCode for rich formatting. You can read the user manual for more info on the template operators we now use.
        <br /><br />&bull; The template system no longer uses the confusing {!eval codes, it's now all done with {{if:}} looking things. See the <a href="http://comiccms.com/docs/" target="_blank">user manual</a> for more info.
        <br /><br />&bull; ComicCMS has been alive just over 2 years now, and over a year of development went into making this new version. Please, if you can spare anything, <a href="http://comiccms.com/donate.php" target="_blank">donate</a> towards our cause and our hosting costs.</p>
        
        <h2>Off you trott</h2>
        <p>Everything has been updated and you're ready to go. You still have the same usernames &amp; passwords so there should be no trouble <a href="../admin/">Signing in</a></p>
        
    </div>
</body>
</html>